import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;

/**
 * 需求：QQ超市，玩到经验最多，钱最多
 * 打开浏览器，登录好QQ超市，运行软件
 * 第一期，自动升级货架，多个超市，
 * 	找到全部的货架坐标，
 * 		判断每一个货架的等级
 * 		判断可用队列数，判断队列剩余时间
 * 		对每一个货架，找到对应的升级按钮的坐标，确定升级按钮坐标
 * 
 * 判断（读取某一坐标颜色，是否是预期值，如果是，判断成功）
 * 
 * @author JiangChi
 *
 */
public class QQSuperMarket {
	private static EventObject fullScreen = new EventObject(new Point(1393,548));
	private static EventObject yingke = new EventObject(new Point(1340,1040));
	private static int UP = 1;
	private static int LEFT = 2;
	private static int DOWN = 3;
	private static int RIGHT = 4;

	public static void main(String[] args) throws MalformedURLException,
			IOException, URISyntaxException, AWTException {
		Robot robot = new Robot();

		robot.delay(3000);
		
		//最好前后两次操作不相邻
//		shengjihuojia(robot,new Huojia(1,5,DOWN,Huojia.FRUIT),1);
//		shengjihuojia(robot,new Huojia(1,7,UP,Huojia.FRUIT),1);
//		
//		shengjihuojia(robot,new Huojia(2,5,DOWN,Huojia.FRUIT),1);
//		shengjihuojia(robot,new Huojia(2,7,UP,Huojia.FRUIT),1);
//		
//		shengjihuojia(robot,new Huojia(3,5,DOWN,Huojia.FRUIT),1);
//		shengjihuojia(robot,new Huojia(3,7,UP,Huojia.FRUIT),1);
//		
//		shengjihuojia(robot,new Huojia(4,5,DOWN,Huojia.DRINK),1);
//		shengjihuojia(robot,new Huojia(4,7,UP,Huojia.DRINK),1);
//		jiasuliangci(robot);
		
		shengjihuojia(robot,new Huojia(5,3,LEFT,Huojia.DRINK),1);
		shengjihuojia(robot,new Huojia(5,4,LEFT,Huojia.DRINK),1);
		jiasuliangci(robot);
		shengjihuojia(robot,new Huojia(5,5,LEFT,Huojia.DRINK),1);
		shengjihuojia(robot,new Huojia(5,7,UP,Huojia.DRINK),1);
		jiasuliangci(robot);
		
		shengjihuojia(robot,new Huojia(6,7,UP,Huojia.DRINK),1);
		
		shengjihuojia(robot,new Huojia(7,3,RIGHT,Huojia.FRUIT),1);
		jiasuliangci(robot);
		shengjihuojia(robot,new Huojia(7,4,RIGHT,Huojia.DRINK),1);
		shengjihuojia(robot,new Huojia(7,5,RIGHT,Huojia.DRINK),1);
		jiasuliangci(robot);
		shengjihuojia(robot,new Huojia(7,6,RIGHT,Huojia.DRINK),1);
		jiasuliangci(robot);
		
	}
	
	
	private static void jiasuliangci(Robot robot) {
//		robot.delay(500);
//		click(robot,new EventObject(new Point(180,90)));//加速队列
		robot.delay(500);
		click(robot,new EventObject(new Point(260,160)));//加速
		robot.delay(500);
		click(robot,new EventObject(new Point(260,160)));//加速
	}


	private static void shengjihuojia(Robot robot, EventObject eo, int time) {
		for (int i = 1; i <= time; i++) {
			robot.delay(1000);
			click(robot,eo);
			robot.delay(500);
			eo.getPoint().setY(eo.getPoint().getY() - 50);
			click(robot,eo);
			robot.delay(500);
			click(robot,new EventObject(new Point(890,614)));
		}
	}
	private static void zuobiao(){
		
	}
	static void click(Robot robot, EventObject eo){
		click(robot, eo.getPoint().getX(), eo.getPoint().getY());
	}
	static void click(Robot robot, int x, int y){
		System.out.println("click:x="+x+",y="+y);
		robot.mouseMove(x, y);
		robot.mousePress(InputEvent.BUTTON1_MASK);
		robot.mouseRelease(InputEvent.BUTTON1_MASK);
	}
}
/**
 * 货架
 * @author JiangChi
 *
 */
class Huojia extends EventObject{
	public static int FRUIT = 1;
	public static int DRINK = 2;
	/**
	 * @param x0 逻辑坐标x
	 * @param y0 逻辑坐标y
	 * @param fangxiang
	 * @param type
	 */
	public Huojia(int x0, int y0, int fangxiang, int type) {
		super();
		this.type = type;
		//1,1 = 960,420
		int x1 = 960;
		int y1 = 420;
		int x = x1 - (x0 - 1) * 40;
		int y = y1 + (x0 - 1) * 20;
		x += (y0 - 1) * 40;
		y += (y0 - 1) * 20;
		if (type == DRINK) {
			y -= 30;
		} else if (type == FRUIT) {
			y -= 30;
		}
		this.setPoint(new Point(x, y));
	}
	private int type;
	private int fangxiang;
	private int level;
	/**
	 * 货架偏移
	 */
	private Point point1;
	/**
	 * 方向偏移
	 */
	private Point point2;
	public Point getPoint1() {
		return point1;
	}
	public void setPoint1(Point point1) {
		this.point1 = point1;
	}
	public Point getPoint2() {
		return point2;
	}
	public void setPoint2(Point point2) {
		this.point2 = point2;
	}
	@Override
	public String toString() {
		return "Huojia [type=" + type + ", fangxiang=" + fangxiang + ", level="
				+ level + ", point1=" + point1 + ", point2=" + point2 + "]";
	}
}
/**
 * 事件对象
 * @author JiangChi
 *
 */
class EventObject {
	/**
	 * 实际坐标（可点击）
	 */
	private Point point;
	/**
	 * 逻辑坐标
	 */
	private Point point0;
	
	public Point getPoint() {
		return point;
	}
	public void setPoint(Point point) {
		this.point = point;
	}
	public EventObject() {
		
	}
	public EventObject(Point point) {
		super();
		this.point = point;
	}
	public Point getPoint0() {
		return point0;
	}
	public void setPoint0(Point point0) {
		this.point0 = point0;
	}
	@Override
	public String toString() {
		return "EventObject [point=" + point + ", point0=" + point0 + "]";
	}
}
/**
 * 实际坐标：屏幕左上角为0，0，横向为x，纵向为y
 * 逻辑坐标：从右上角（正上方的角）开始计算坐标，往左下方向为x，往右下方向为y
 * @author JiangChi
 *
 */
class Point {
	private int x;
	private int y;
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public Point(int x, int y) {
		super();
		this.x = x;
		this.y = y;
	}
	@Override
	public String toString() {
		return "Point [x=" + x + ", y=" + y + "]";
	}
}
